package com.zhledu.algorithm;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class HuiwenDate {
    public static void main(String[] args) throws ParseException {
        Scanner scanner = new Scanner(System.in);
        int sdate = scanner.nextInt();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Calendar c = Calendar.getInstance();
        Date date = sdf.parse(String.valueOf(sdate));
        c.setTime(date);
        Date endDate = sdf.parse("89991231");
        Date startDate=sdf.parse("10000101");
        boolean flag = false;
        c.add(Calendar.DAY_OF_YEAR,1);
        date=c.getTime();
        while (date.before(endDate)&&date.after(startDate)) {
            String s = sdf.format(date);
            if (s.charAt(0) == s.charAt(7) && s.charAt(1) == s.charAt(6) && s.charAt(2) == s.charAt(5) && s.charAt(3) == s.charAt(4)) {
                if (!flag) {
                    System.out.println(s);
                    flag=true;
                }
                if (s.charAt(0) == s.charAt(2) && s.charAt(1) == s.charAt(3)) {
                    System.out.println(s);
                    break;
                }
            }
            c.add(Calendar.DAY_OF_YEAR, 1);
            date = c.getTime();
        }
    }


}
